import { v4 as uuidv4 } from 'uuid';
export default {
  use(app, knex){
    app.post('/login', function(req, res){
      console.log(req.body)
      
      knex('user').select('*').then( rows =>{
        res.send({
          code: 0,
          data: rows
        })
    
      })
    })

    app.get('/logout', function(req, res){
      knex('user').insert({'username': 'xiaoming'}).then( rows =>{
        res.send('inserted')
      })
    })
    //系统编码
    app.get('/sysParams', function(req, res){
      knex.raw('SELECT group_name, code, name FROM code ORDER BY group_name').then( rows =>{
        let data = {};
        rows.forEach(row => {
          const d = {name: row.name, code: row.code};
          if(data[row.group_name] == undefined ) data[row.group_name] = [d];
          else data[row.group_name].push(d)
        });
        res.send({
          code: 0,
          data: data
        })
      })
    })

  }

}

